import axios from 'axios'
import { Message } from 'element-ui'

const instance = axios.create({
    baseURL: 'http://localhost:10086/',
    timeout: 3 * 1000,
    responseType: 'json',
    responseEncoding: 'UTF-8',
    //headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' }
})

//请求拦截器
instance.interceptors.request.use(
    config => {
     return config
},error => {
    Message({
        message: '请求错误!',
        type: 'error',
        showClose: true,
        duration: 1000,
        center: true
    })
    return Promise.reject(error);
})
//响应拦截器
instance.interceptors.response.use(res => {
    
    // console.log('响应拦截器instance.interceptors.response.use():',res.data)
    return res.data
},error => {
    Message({
        message: '响应错误!',
        type: 'error',
        showClose: true,
        duration: 1000,
        center: true
    })
    return Promise.reject(error);
})

export default instance